cmake_minimum_required(VERSION 3.0.0)
project(voice-assistant VERSION 0.1.0 LANGUAGES C)

# 编译 IntelPubTrans.c 成为库文件
add_library(IntelPubTrans IntelPubTrans.c)
target_include_directories(IntelPubTrans PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

# 添加你的其他可执行文件
add_executable(control control.c)
target_link_libraries(control asound)

add_executable(play play.c)
target_link_libraries(play asound)

# 确保led目标名称唯一
add_executable(led_app led.c)

# 确保key目标名称唯一
add_executable(key_app key.c record.c)
target_link_libraries(key_app gpiod asound)

add_subdirectory(snowboy)
add_executable(wake wake.c record.c stt.c token.c http.c config.c)
target_link_libraries(wake snowboy-wrapper snowboy-detect cblas m stdc++ asound curl cjson)
target_compile_definitions(wake PRIVATE _GNU_SOURCE)

add_executable(jrsc jrsc.c)
target_link_libraries(jrsc curl cjson)

# 删除重复的led可执行文件
# add_executable(led led.c)

# 将 chat 功能分离为库
add_library(chat_lib chat.c config.c http.c)
target_link_libraries(chat_lib cjson curl)
target_compile_definitions(chat_lib PRIVATE _GNU_SOURCE)

# # 创建 chat 可执行文件
# add_executable(chat chat.c)
# target_link_libraries(chat chat_lib)

add_executable(utils utils.c)
target_link_libraries(utils uuid resolv)

# 文字转语音功能
add_library(tts tts.c config.c http.c play.c)
target_link_libraries(tts cjson curl uuid resolv asound)
target_compile_definitions(tts PRIVATE _GNU_SOURCE)

# 关键功能，包含录音和唤醒，确保key目标名称唯一
add_executable(key_main key.c record.c wake.c tts.c IntelPubTrans.c stt.c token.c http.c config.c)
# target_link_libraries(key_main gpiod asound snowboy-wrapper snowboy-detect cblas m stdc++ curl cjson pthread chat tts resolv)
target_link_libraries(key_main gpiod asound snowboy-wrapper snowboy-detect cblas m stdc++ curl cjson pthread chat_lib tts resolv)
target_compile_definitions(key_main PRIVATE _GNU_SOURCE)

# 添加 chat.h 头文件路径
target_include_directories(key_main PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
